//
//  SISSButton.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/16.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSButton.h"

@implementation SISSButton

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat imageWith = self.imageView.frame.size.width;
    CGFloat imageHeight = self.imageView.frame.size.height;
    
    CGFloat labelWidth = 0.0;
    CGFloat labelHeight = 0.0;
    CGFloat space = 8.0;
    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
        // 由于iOS8中titleLabel的size为0，用下面的这种设置
        labelWidth = self.titleLabel.intrinsicContentSize.width;
        labelHeight = self.titleLabel.intrinsicContentSize.height;
    } else {
        labelWidth = self.titleLabel.frame.size.width;
        labelHeight = self.titleLabel.frame.size.height;
    }
    
    UIEdgeInsets imageEdgeInsets = UIEdgeInsetsMake(-labelHeight-space/2.0, 0, 0, -labelWidth);
    UIEdgeInsets labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith, -imageHeight-space/2.0, 0);
    
    self.titleEdgeInsets = labelEdgeInsets;
    self.imageEdgeInsets = imageEdgeInsets;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    self.titleLabel.textColor = COLOR(0x334A60);
}


@end
